<%--
  Created by IntelliJ IDEA.
  User: 17598
  Date: 2023/10/10
  Time: 15:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>员工审核</title>
    <link rel="stylesheet" href="../../static/css/element-ui.css">
    <script src="../../static/js/vue.js"></script>
    <script src="../../static/js/axios.min.js"></script>
    <script src="../../static/js/element_index.js"></script>
</head>
<body>
<div id="app">

    <%--表格组件--%>
    <el-form :inline="true" :model="searchForm">
        <el-form-item label="">
            <el-select v-model="searchForm.branchid" placeholder="请选择要查询的分店">
                <el-option v-for="item in branchInfoList" :key="item.branchid" :label="item.branchname"
                           :value="item.branchid"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item>
            <el-button type="success" @click="initTable" icon="el-icon-search">查询</el-button>
        </el-form-item>
    </el-form>
    <div v-if="staffex.length>0">
        <el-table :data="staffex" style="width: 100%">
            <el-table-column prop="id" label="ID">
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="employee" label="员工姓名">
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="oldBranchName" label="旧分店">
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="oldDeptName" label="旧部门">
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="newBranchName" label="新分店">
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="newDeptName" label="新部门"></el-table-column>
            <el-table-column show-overflow-tooltip prop="staffTransfer.applytime" label="申请时间">
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="applicantName" label="申请人">
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="staffTransfer.extime" label="审核时间">
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="reviewedName" label="审核人">
            </el-table-column>
            <el-table-column prop="staffTransfer.state" label="状态">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.staffTransfer.state==1">待审核</el-tag>
                    <el-tag type="info" v-if="scope.row.staffTransfer.state==2">审核通过</el-tag>
                    <el-tag type="warring" v-if="scope.row.staffTransfer.state==3">已驳回</el-tag>
                </template>
            </el-table-column>
            <el-table-column fixed="right" label="操作" width="300px">
                <template slot-scope="scope">
                    <el-row v-if="scope.row.staffTransfer.state==1">
                        <el-button type="primary" size="mini" @click="passedAudit(scope.row,2)">通过</el-button>
                        <el-button type="danger" size="mini" @click="passedAudit(scope.row,3)">驳回</el-button>
                    </el-row>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
                @size-change="staffexSizeChange"
                @current-change="staffexCurrentChange"
                :current-page="current"
                :page-sizes="[5, 10, 15, 20]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
        </el-pagination>
    </div>
    <div v-else>
        <el-empty description="该查询暂无审核数据！">
            <el-button @click="flushed" type="primary">点击刷新</el-button>
        </el-empty>
    </div>
</div>
<script>
    let app = new Vue({
        el: "#app",
        data: {
            //搜索表单
            searchForm: {
                branchid: undefined
            },
            //所有员工审核信息的信息
            staffex: [],
            //总条数
            total: 0,
            //每页显示的大小
            pageSize: 5,
            //当前页码
            current: 1,
            //所有店名
            branchInfoList: [],
            userInfo: {}
        },
        created() {
            this.initUserInfo();
            this.initTable();
            this.initBranchInfo();
        },
        methods: {
            initUserInfo() {
                axios.get('/staff/info1').then(res => {
                    this.userInfo = res.data.data;
                })
            },
            initTable() {
                axios.get("/staffEx/getAllInfo", {
                    params: {
                        current: this.current,
                        pageSize: this.pageSize,
                        branchid: this.searchForm.branchid,
                    }
                }).then(function (resp) {
                    app.staffex = resp.data.data.rows;
                    app.total = resp.data.data.total;
                })
            },
            initBranchInfo() {
                axios.get("/staffEx/getAllBranch").then(function (resp) {
                    app.branchInfoList = resp.data.data
                })
            },
            /*设置每页展示的数量*/
            staffexSizeChange(val) {
                this.pageSize = val;
                this.initTable();
            },
            /*修改当前页数*/
            staffexCurrentChange(val) {
                this.current = val;
                this.initTable();
            },
            /*模糊查询提交*/
            flushed() {
                this.searchForm.branchid = undefined;
                this.initTable();
            },
            /*通过审核*/
            passedAudit(row, status) {
                let form = row;
                form.state = status;
                if (row.newbranchid !== this.userInfo.branchid) {
                    this.$message('对不起，你没有权限审核该分店员工！');
                    return;
                } else {
                    if (status === 2) {
                        this.$confirm('确定通过吗?', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(() => {
                            axios.post('/staffEx/updateStatus', form).then(res => {
                                this.$message.success('操作成功');
                                this.initTable();
                            })
                        }).catch(() => {
                            this.$message({
                                type: 'info',
                                message: '已取消通过'
                            });
                        });
                    } else if (status === 3) {
                        this.$confirm('确定驳回吗?', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(() => {
                            axios.post('/staffEx/updateStatus', form).then(res => {
                                this.$message.success('操作成功');
                                this.initTable();
                            })
                        }).catch(() => {
                            this.$message({
                                type: 'info',
                                message: '已取消驳回'
                            });
                        });
                    }
                }
            }
        }
    })
</script>
</body>
</html>
